package com.patterns.flyweight;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * FlyweightFactory享元工厂类
 * @author huangke
 *
 */
public class ChessFlyweightFactory {
	//享元池，存储享元对象
	private static Map<String,ChessFlyweight> pool = new ConcurrentHashMap<String, ChessFlyweight>();
	
	
	//根据颜色获得棋子
	public static ChessFlyweight getChess(String color){
		if(pool.get(color) != null){
			return pool.get(color);
		}else{
			ChessFlyweight chess = new ChessConcreteFlyweight(color);
			pool.put(color, chess);
			return chess;
		}
	}
}
